package springboot.example.springboot.common;


import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import springboot.example.springboot.tools.JsonMapper;

import java.util.HashMap;
import java.util.Map;

@Controller
public class BaseController {

    public String fail(String message) {
        Map map = new HashMap();
        map.put("status", 0);
        map.put("message", message);
        return JsonMapper.toJsonString(map);
    }

    public String success(String message, Model model) {
        model.addAttribute("message",message);
        model.addAttribute("status",1);
        return JsonMapper.toJsonString(model);
    }

    public String success(String message) {
        Map map = new HashMap();
        map.put("message",message);
        map.put("status",1);

        return JsonMapper.toJsonString(map);
    }
}
